(function() {
    angular.module('app').factory('monitorDayComponentService', monitorDayComponentService);

    monitorDayComponentService.$inject = ['util', '$q'];

    function monitorDayComponentService(util, $q) {
        return {
            get: _get,
            getShop: _getShop
        }

        /**
         * [_get description]
         * @param  {[type]} targetId [description]
         * @param  {[type]} dim      [sellMoney,sellAmount]
         * @return {[type]}          [description]
         */
        function _get(targetId) {

            var defer = $q.defer();

            util.$get({
                url: '/marketconditions/collection/getCollectionDaySellInfo.htm',
                data: {
                    partition: 'day',
                    targetId: targetId
                }
            }).then(function(resp) {
                var data = {
                    x: [],
                    sellMoney: [],
                    sellAmount: []
                }
                angular.forEach(resp.value, function(item) {
                    data.x.push(item.key.slice(5, 10));
                    data.sellMoney.push(item.value['sellMoney']);
                    data.sellAmount.push(item.value['sellAmount']);
                });

                defer.resolve(data);
            }, function(err) {
                defer.reject(err);
            });

            return defer.promise;
        }


        function _getShop(targetId) {
            var defer = $q.defer();

            util.$get({
                url: '/marketconditions/collection/getCollectionDaySellInfo.htm',
                data: {
                    partition: 'day',
                    type: 'shop',
                    targetId: targetId
                }
            }).then(function(resp) {
                var data = {
                    x: [],
                    sellMoney: [],
                    sellAmount: []
                }
                angular.forEach(resp.value, function(item) {
                    data.x.push(item.key.slice(5, 10));
                    data.sellMoney.push(item.value['sellMoney']);
                    data.sellAmount.push(item.value['sellAmount']);
                });

                defer.resolve(data);
            }, function(err) {
                defer.reject(err);
            });

            return defer.promise;
        }
    }
})();
